<template>

    <el-button type="primary" circle @click="dialogFormVisible = true" class="float-right" >
      <el-icon :size="20" style="vertical-align: middle;">
        <Plus/>
      </el-icon>
    </el-button>
    <el-dialog id="AddDiscussTopicDialog" v-model="dialogFormVisible" title="新增讨论">
      <el-form>
        <el-form-item label="讨论标题" :label-width="formLabelWidth">
          <el-input v-model="form.topic" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="讨论内容" :label-width="formLabelWidth">
          <qul-edit :ref="'qul'"></qul-edit>
        </el-form-item>

      </el-form>
      <template style="padding-top: 200px" #footer>
      <span class="dialog-footer" style="margin-top: 12px">
        <el-button @click="dialogFormVisible = false">Cancel</el-button>
        <el-button type="primary" @click="upload()"
        >Confirm</el-button>
      </span>
      </template>
    </el-dialog>


</template>

<script>
import axios from "axios";
import {defineComponent, reactive, toRefs} from 'vue'
import QulEdit from "./qulEdit";
import {Plus} from "@element-plus/icons-vue";
import {ElMessage} from "element-plus";

export default {
  name: "AddDiscussTopicDialog",
  components: {Plus, QulEdit},
  setup() {
    const state = reactive({
      dialogFormVisible: false,
      form: {
        topic: '',
        content: '',
      },
      formLabelWidth: '120px',

    })

    return {
      ...toRefs(state),
    }
  },
  methods: {

    upload() {
      this.form.content = this.$refs.qul.covert2Html()
      this.dialogFormVisible = false
      axios.post("/api/teacher/AddNewDiscussTopic", this.form).then((res) => {
        if (res.status === 200) {
          ElMessage.success({message: '成功'})
          this.$parent.setUpData()
        }
      })
    }
  }
}
</script>

<style>

.el-dialog .el-dialog__footer {
  margin-top: 60px !important;
}
</style>